package com.example.shoppingmall.cotroller;

import com.example.shoppingmall.Utils.Page;
import com.example.shoppingmall.config.MyLog;
import com.example.shoppingmall.pojo.Return;
import com.example.shoppingmall.service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/aftersale")
public class AfterSaleController {
    @Autowired
    AfterSaleService afterSaleService;

    @RequestMapping("/aftersalelist")
    public String aftersalelist(@RequestParam(value = "after",required = false) String after, @RequestParam(value = "odno",required = false) String odno,
                                @RequestParam(value = "examine",required = false) String examine, @RequestParam(value = "status",required = false) String status,
                                @RequestParam(value = "rphone",required = false) String rphone, @RequestParam(value = "rorderno",required = false) String rorderno,
                                @RequestParam(value = "aftersale",required = false) String aftersale, @RequestParam(value = "pageno",defaultValue = "1") String pageno,
                                @RequestParam(value = "pageSize",defaultValue = "6") String pageSize, Model model){
            model.addAttribute("rphone",rphone);
            model.addAttribute("rorderno",rorderno);
            model.addAttribute("aftersale",aftersale);
            if(examine==null){
                examine="0";
            }
            if(status==null){
                status="0";
            }
            int count=afterSaleService.rcount(rphone,rorderno,examine,status,aftersale);
            int num=(Integer.valueOf(pageno)-1)*Integer.valueOf(pageSize);
            Page page=new Page();
            page.setPageno(Integer.valueOf(pageno));
            page.setPageCount(count);
            List<Return> returnList=afterSaleService.getReturnlist(after,odno,examine,status,rphone,rorderno,aftersale,num,Integer.valueOf(pageSize));
            model.addAttribute("page",page);
            model.addAttribute("returnList",returnList);
            return "order/Aftersalelist";
    }

    //售后查看详情
    @MyLog(value = "订单管理->售后单->查看明细")
    @RequestMapping("/selafter")
    @ResponseBody
    public Map<Object,Object> selafter(Integer id){
        Map<Object,Object> map=new HashMap<>();
        Return returnlist=afterSaleService.selafter(id);
        map.put("returns",returnlist);
        return map;
    }
}
